************************************************************************************************************************************************
************************ Using Rich Lists to Study the Super-Rich and Top Wealth Inequality: Insights from Switzerland *************************
************************************************************************************************************************************************

clear all
set more off
set scheme s1color  

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: April, 4 2024

***************************************************************************************************************************************************
***** How Persistent is wealth at the very top?
***************************************************************************************************************************************************

** Chapter 4.1: Inherited vs. Self-made wealth **
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

collapse (count) id_pers, by (year wealth_origin)

egen total_obs = sum(id_pers), by(year)
egen married_obs = mean(id_pers) if wealth_origin==1 , by(year)
egen inherited_obs = mean(id_pers) if wealth_origin==2 , by(year)
egen selfmade_obs = mean(id_pers) if wealth_origin==3 , by(year)
		
collapse (mean) total_obs (sum) married_obs (sum) inherited_obs (sum) selfmade_obs, by (year)

gen married_obs_sh = married_obs / total_obs
gen inherited_obs_sh = inherited_obs / total_obs
gen selfmade_obs_sh = selfmade_obs / total_obs
		
label var married_obs_sh "married "		
label var inherited_obs_sh	"inherited "		
label var selfmade_obs_sh "self-made"		

cd "$mypath/output/figures/"

graph bar (asis) inherited_obs_sh selfmade_obs_sh married_obs_sh, over(year, label(angle(90) labsize(normalsize))) percentages stack bar(1, fcolor(black) lcolor(black)) bar(2, fcolor(gs10) lcolor(black)) bar(3, fcolor(white) lcolor(black))  ///
legend(row(1) size(normalsize)) ytitle("in % of all ranking entries", size(normalsize)) ylab(, labsize(normalsize) grid gmin gmax) 

graph export "selfmade_inherited.pdf", replace

		
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear
			
collapse (sum) wealth_R, by (year foreignborn wealth_origin)
	
* generate outcomes for wealth by origin	
egen totalW = sum(wealth_R), by(year)
egen marriedW_all = sum(wealth_R) if wealth_origin==1 , by(year)
egen inheritedW_all = sum(wealth_R) if wealth_origin==2 , by(year)
egen selfmadeW_all = sum(wealth_R) if wealth_origin==3 , by(year)		
	
* generate outcomes for wealth by origin for swiss-born only 
egen marriedW_swiss = sum(wealth_R) if wealth_origin==1 & foreignborn==0, by(year)
egen inheritedW_swiss = sum(wealth_R) if wealth_origin==2 & foreignborn==0, by(year)
egen selfmadeW_swiss = sum(wealth_R) if wealth_origin==3 & foreignborn==0, by(year)
	
* genertate outcomes for wealth by origin for foreign born only 
egen marriedW_foreign = sum(wealth_R) if wealth_origin==1 & foreignborn==1, by(year)
egen inheritedW_foreign = sum(wealth_R) if wealth_origin==2 & foreignborn==1, by(year)
egen selfmadeW_foreign = sum(wealth_R) if wealth_origin==3 & foreignborn==1, by(year)
	
collapse (mean) totalW (mean) marriedW_all (mean) inheritedW_all (mean) selfmadeW_all (mean) marriedW_swiss (mean) inheritedW_swiss ///
(mean) selfmadeW_swiss (mean) marriedW_foreign (mean) inheritedW_foreign (mean) selfmadeW_foreign, by (year)

replace marriedW_swiss=0 if marriedW_swiss==.
replace marriedW_foreign=0 if marriedW_foreign==.
	
gen sh_inherit_all = 1 - (selfmadeW_all / totalW)
gen sh_inherit_swiss = 1 - (selfmadeW_swiss / (selfmadeW_swiss + inheritedW_swiss + marriedW_swiss))
gen sh_inherit_foreign = 1 - (selfmadeW_foreign / (selfmadeW_foreign + inheritedW_foreign + marriedW_foreign))
		
label var sh_inherit_all "all super-rich"
label var sh_inherit_swiss "Swiss-borns"
label var sh_inherit_foreign "foreign-borns"	
	
cd "$mypath/output/figures/"
		
tw  (connect sh_inherit_all year if year>=1989, msymb(O) mcolor(gs0) msize() lcolor(gs0) lpattern())    ///
	(connect sh_inherit_swiss year if year>=1989, msymb(D) mcolor(gs7) msize() lcolor(gs7) lpattern())    ///
	(connect sh_inherit_foreign year if year>=1989, msymb(T) mcolor(gs11) msize() lcolor(gs11) lpattern())    ///
	, ytitle("non-self-made wealth in % of total", size(normalsize)) xtitle("")  ///
	ylab(0.4 "40%" 0.5 "50%" 0.6 "60%" 0.7 "70%" 0.8 "80%" 0.9 "90%", labsize(normalsize) grid gmin gmax) xlab(1990(5)2020, labsize(normalsize) grid gmin gmax) ///
	legend(row(1) size(normalsize)) 
	
	graph export "non-selfmade.pdf", as(pdf) replace

	
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear
	
* Share of top wealth prior to WW2	
collapse (sum) wealth_R, by (year old_wealth_ww2)

egen totalW = mean(wealth_R), by(year)
egen oldW = mean(wealth_R) if old_wealth_ww2==1 , by(year)
egen newW = mean(wealth_R) if old_wealth_ww2==0 , by(year)

collapse (sum) totalW (sum) oldW (sum) newW, by (year)

gen oldW_sh = oldW / totalW
gen newW_sh = newW / totalW

cd "$mypath/output/figures/"

tw  (connect oldW_sh year if year>=1989, msymb(O) mcolor(black) msize() lcolor(black) lpattern())    ///
	, ytitle("in % of total bilanz wealth", size()) xtitle("") xline(1993, lpattern(longdash) lcolor(darkgray)) ///
	ylab(0.3 "30%" 0.4 "40%" 0.5 "50%" 0.6 "60%" 0.7 "70%", grid gmin gmax) xlab(1990(5)2020, grid gmin gmax) legend( size(small)) 
	
	graph export "WW2.pdf", as(pdf) replace
		
	
	
	
** Chapter 4.2: Survival Rates of Dynasties **
** dynastie analysis**

* 2000-2010 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

forvalues i=2000/2010{
    gen id_`i' = id_fam if year==`i' 
  }

collapse (count) id_2000 (count) id_2001 (count) id_2002 (count) id_2003 (count) id_2004 ///
(count) id_2005 (count) id_2006 (count) id_2007 (count) id_2008 (count) id_2009 (count) id_2010, by (id_fam year)

egen indicator= sum(id_2000), by(id_fam)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2000==1 
replace survival=2 if id_2001==1 
replace survival=3 if id_2002==1 
replace survival=4 if id_2003==1 
replace survival=5 if id_2004==1 
replace survival=6 if id_2005==1 
replace survival=7 if id_2006==1 
replace survival=8 if id_2007==1 
replace survival=9 if id_2008==1 
replace survival=10 if id_2009==1 
replace survival=11 if id_2010==1 

drop if survival==.

collapse (count) survival, by (year)

gen time = _n
gen sur_fun_00_10 = survival / survival[1]
drop survival year

tempfile surviv_fam_0010
save "`surviv_fam_0010'"


* 2005-2015 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

drop if year <2005

forvalues i=2005/2015 {
    gen id_`i' = id_fam if year==`i' 
  }

collapse (count) id_2005 (count) id_2006 (count) id_2007 (count) id_2008 ///
(count) id_2009 (count) id_2010 (count) id_2011 (count) id_2012 (count) id_2013 (count) id_2014 (count) id_2015, by (id_fam year)

egen indicator= sum(id_2005), by(id_fam)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2005==1 
replace survival=2 if id_2006==1 
replace survival=3 if id_2007==1 
replace survival=4 if id_2008==1 
replace survival=5 if id_2009==1 
replace survival=6 if id_2010==1 
replace survival=7 if id_2011==1 
replace survival=8 if id_2012==1 
replace survival=9 if id_2013==1 
replace survival=10 if id_2014==1 
replace survival=11 if id_2015==1 

drop if survival==.

collapse (count) survival, by (year)

gen time = _n
gen sur_fun_05_15 = survival / survival[1]
drop survival year

tempfile surviv_fam_0515
save "`surviv_fam_0515'"



* 2010-2020 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

drop if year <2010

forvalues i=2010/2020 {
    gen id_`i' = id_fam if year==`i' 
  }

collapse (count) id_2010 (count) id_2011 (count) id_2012 (count) id_2013 (count) id_2014 ///
(count) id_2015 (count) id_2016 (count) id_2017 (count) id_2018 (count) id_2019 (count) id_2020, by (id_fam year)

egen indicator= sum(id_2010), by(id_fam)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2010==1 
replace survival=2 if id_2011==1 
replace survival=3 if id_2012==1 
replace survival=4 if id_2013==1 
replace survival=5 if id_2014==1 
replace survival=6 if id_2015==1 
replace survival=7 if id_2016==1 
replace survival=8 if id_2017==1 
replace survival=9 if id_2018==1 
replace survival=10 if id_2019==1 
replace survival=11 if id_2020==1 

drop if survival==.


collapse (count) survival, by (year)

gen time = _n
gen sur_fun_10_20 = survival / survival[1]
drop survival year

tempfile surviv_fam_1020
save "`surviv_fam_1020'"


* 2015-2020 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

drop if year <2015

forvalues i=2015/2020 {
    gen id_`i' = id_fam if year==`i' 
  }

collapse (count) id_2015 (count) id_2016 (count) id_2017 (count) id_2018 (count) id_2019 (count) id_2020, by (id_fam year)

egen indicator= sum(id_2015), by(id_fam)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2015==1 
replace survival=2 if id_2016==1 
replace survival=3 if id_2017==1 
replace survival=4 if id_2018==1  
replace survival=5 if id_2019==1  
replace survival=6 if id_2020==1 

drop if survival==.

collapse (count) survival, by (year)

gen time = _n
gen sur_fun_15_20 = survival / survival[1]
drop survival year

tempfile surviv_fam_1520
save "`surviv_fam_1520'"

clear all
* combine  
use "`surviv_fam_0010'"
merge 1:1 time using "`surviv_fam_0515'", nogen
merge 1:1 time using "`surviv_fam_1020'", nogen
merge 1:1 time using "`surviv_fam_1520'", nogen

label var sur_fun_00_10 "2000-2010"
label var sur_fun_05_15 "2005-2015"
label var sur_fun_10_20 "2010-2020"
label var sur_fun_15_20 "2015-2020"

replace time = time -1 
	
cd "$mypath/output/figures/"
		
tw  (connect sur_fun_00_10 time if time>=0, msymb(O) mcolor(gs0) msize() lcolor(gs0) lpattern())    ///
	(connect sur_fun_05_15 time if time>=0, msymb(D) mcolor(gs7) msize() lcolor(gs7) lpattern())    ///
	(connect sur_fun_10_20 time if time>=0, msymb(T) mcolor(gs11) msize() lcolor(gs11) lpattern())    ///
	(connect sur_fun_15_20 time if time>=0, msymb(Sh) mcolor(gs0) msize() lcolor(gs0) lpattern())    ///
	, ytitle("in % of total observation", size(normalsize)) xtitle("Years", size(normalsize)) ///
	ylab(0.5 "50%" 0.6 "60%" 0.7 "70%" 0.8 "80%" 0.9 "90%" 1 "100%", labsize(normalsize) grid gmin gmax) xlab(0(1)10, labsize(normalsize) grid gmin gmax) ///
	legend(row(2) size(normalsize)) 
	
	graph export "survival_fam_0020.pdf", as(pdf) replace	
	
	
	
** individual-level analysis**
clear all	
* 2000-2010 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

forvalues i=2000/2010{
    gen id_`i' = id_pers if year==`i' 
 }

collapse (count) id_2000 (count) id_2001 (count) id_2002 (count) id_2003 (count) id_2004 ///
(count) id_2005 (count) id_2006 (count) id_2007 (count) id_2008 (count) id_2009 (count) id_2010, by (id_pers year)

egen indicator= sum(id_2000), by(id_pers)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2000==1 
replace survival=2 if id_2001==1 
replace survival=3 if id_2002==1 
replace survival=4 if id_2003==1 
replace survival=5 if id_2004==1 
replace survival=6 if id_2005==1 
replace survival=7 if id_2006==1 
replace survival=8 if id_2007==1 
replace survival=9 if id_2008==1 
replace survival=10 if id_2009==1 
replace survival=11 if id_2010==1 

drop if survival==.


collapse (count) survival, by (year)

gen time = _n
gen sur_fun_00_10 = survival / survival[1]
drop survival year

tempfile surviv_ind_0010
save "`surviv_ind_0010'"

* 2005-2015 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

drop if year <2005

forvalues i=2005/2015 {
    gen id_`i' = id_pers if year==`i' 
  }


collapse (count) id_2005 (count) id_2006 (count) id_2007 (count) id_2008 ///
(count) id_2009 (count) id_2010 (count) id_2011 (count) id_2012 (count) id_2013 (count) id_2014 (count) id_2015, by (id_pers year)

egen indicator= sum(id_2005), by(id_pers)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2005==1 
replace survival=2 if id_2006==1 
replace survival=3 if id_2007==1 
replace survival=4 if id_2008==1 
replace survival=5 if id_2009==1 
replace survival=6 if id_2010==1 
replace survival=7 if id_2011==1 
replace survival=8 if id_2012==1 
replace survival=9 if id_2013==1 
replace survival=10 if id_2014==1 
replace survival=11 if id_2015==1 

drop if survival==.

collapse (count) survival, by (year)

gen time = _n
gen sur_fun_05_15 = survival / survival[1]
drop survival year

tempfile surviv_ind_0515
save "`surviv_ind_0515'"

* 2010-2020 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

drop if year <2010

forvalues i=2010/2020 {
    gen id_`i' = id_pers if year==`i' 
  }

collapse (count) id_2010 (count) id_2011 (count) id_2012 (count) id_2013 (count) id_2014 ///
(count) id_2015 (count) id_2016 (count) id_2017 (count) id_2018 (count) id_2019 (count) id_2020, by (id_pers year)

egen indicator= sum(id_2010), by(id_pers)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2010==1 
replace survival=2 if id_2011==1 
replace survival=3 if id_2012==1 
replace survival=4 if id_2013==1 
replace survival=5 if id_2014==1 
replace survival=6 if id_2015==1 
replace survival=7 if id_2016==1 
replace survival=8 if id_2017==1 
replace survival=9 if id_2018==1 
replace survival=10 if id_2019==1 
replace survival=11 if id_2020==1 

drop if survival==.

collapse (count) survival, by (year)

gen time = _n
gen sur_fun_10_20 = survival / survival[1]
drop survival year

tempfile surviv_ind_1020
save "`surviv_ind_1020'"

* 2015-2020 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

drop if year <2015

forvalues i=2015/2020 {
    gen id_`i' = id_pers if year==`i' 
  }


collapse (count) id_2015 (count) id_2016 (count) id_2017 (count) id_2018 (count) id_2019 (count) id_2020, by (id_pers year)

egen indicator= sum(id_2015), by(id_pers)
drop if indicator==0

gen survival=. 
replace survival=1 if id_2015==1 
replace survival=2 if id_2016==1 
replace survival=3 if id_2017==1 
replace survival=4 if id_2018==1  
replace survival=5 if id_2019==1  
replace survival=6 if id_2020==1 

drop if survival==.

collapse (count) survival, by (year)

gen time = _n
gen sur_fun_15_20 = survival / survival[1]
drop survival year

tempfile surviv_ind_1520
save "`surviv_ind_1520'"

clear all
* combine data 
use "`surviv_ind_0010'"
merge 1:1 time using "`surviv_ind_0515'", nogen
merge 1:1 time using "`surviv_ind_1020'", nogen
merge 1:1 time using "`surviv_ind_1520'", nogen

label var sur_fun_00_10 "2000-2010"
label var sur_fun_05_15 "2005-2015"
label var sur_fun_10_20 "2010-2020"
label var sur_fun_15_20 "2015-2020"

replace time = time -1 
cd "$mypath/output/figures/"
		
tw  (connect sur_fun_00_10 time if time>=0, msymb(O) mcolor(gs0) msize() lcolor(gs0) lpattern())    ///
	(connect sur_fun_05_15 time if time>=0, msymb(D) mcolor(gs7) msize() lcolor(gs7) lpattern())    ///
	(connect sur_fun_10_20 time if time>=0, msymb(T) mcolor(gs11) msize() lcolor(gs11) lpattern())    ///
	(connect sur_fun_15_20 time if time>=0, msymb(Sh) mcolor(gs0) msize() lcolor(gs0) lpattern())    ///
	, ytitle("in % of total observation", size(normalsize)) xtitle("Years", size(normalsize)) ///
	ylab(0.5 "50%" 0.6 "60%" 0.7 "70%" 0.8 "80%" 0.9 "90%" 1 "100%", labsize(normalsize) grid gmin gmax) xlab(0(1)10, labsize(normalsize) grid gmin gmax) ///
	legend(row(2) size(normalsize)) 
	
	graph export "survival_ind_0020.pdf", as(pdf) replace	
	
	
** Chapter 4.3: Intragenerational Wealth Mobility **

** dynastie analysis 2000-2010**
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear
	
keep if year==2000 | year==2005 | year==2010 
sort id_fam year				
	
gen wealth_R_00 = .
replace wealth_R_00 = wealth_R if year==2000
gen wealth_R_05 = .
replace wealth_R_05 = wealth_R if year==2005
gen wealth_R_10 = .
replace wealth_R_10 = wealth_R if year==2010

collapse (mean) wealth_R_00 (mean) wealth_R_05 (mean) wealth_R_10, by(id_fam)

tab wealth_R_00
/// tab 270 observations
drop if wealth_R_00==.

sum wealth_R_00 wealth_R_05 wealth_R_10
///105 drop-outs
preserve
keep if wealth_R_10==.
keep if wealth_R_00 <200
sum id_fam
restore 
///30 with below 0.2b wealth_R

gen wealth_R_00_LN = ln(wealth_R_00)
gen wealth_R_05_LN = ln(wealth_R_05)
gen wealth_R_10_LN = ln(wealth_R_10)

reg wealth_R_05_LN wealth_R_00_LN
reg wealth_R_10_LN wealth_R_00_LN

label var wealth_R_05_LN "2005"
label var wealth_R_10_LN "2010"

*install packages
ssc install grstyle, replace
ssc install palettes, replace
ssc install colrspace, replace

grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1
grstyle set legend 10, inside nobox
grstyle set ci, opacity(40) 

cd "$mypath/output/figures/"

twoway (scatter wealth_R_05_LN wealth_R_00_LN, msymb(O) mcolor(black%60) msize()) ///
(scatter wealth_R_10_LN wealth_R_00_LN, msymb(D) mcolor(gs11%60) msize()) ///
(lfitci wealth_R_05_LN wealth_R_00_LN, clstyle(black) lwidth() ) ///
(lfitci wealth_R_10_LN wealth_R_00_LN, clstyle(gs11)) ///
, ytitle("real log wealth 2005 resp. 2010", size(normalsize)) xtitle("real log wealth 2000", size(normalsize)) ylab(5(1)10, labsize(normalsize) grid gmin gmax) xlab(5(1)10, labsize(normalsize) grid gmin gmax) ///
legend(order(1 "2005" 2 "2010") size(normalsize)) note("105 of 270 observations (39%) drop out from 2000 to 2010." ///
"30 of the 105 drop out obs. (29%) had a net wealth of <0.2 billion in 2000.", size(small)) text(8.2 9.6 "{&beta} = 0.80" "R{superscript:2} = 0.67", size(normalsize) color(gs11)) ///
text(9.6 9.1 "{&beta} = 0.87" "R{superscript:2} = 0.82", size(normalsize) color(black))

graph export "mob_corr_fam_0010.pdf", as(pdf) replace


** dynastie analysis: 2010-2020**
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

keep if year==2010 | year==2015 | year==2020 
sort id_fam year				
	
gen wealth_R_10 = .
replace wealth_R_10 = wealth_R if year==2010
gen wealth_R_15 = .
replace wealth_R_15 = wealth_R if year==2015
gen wealth_R_20 = .
replace wealth_R_20 = wealth_R if year==2020

collapse (mean) wealth_R_10 (mean) wealth_R_15 (mean) wealth_R_20, by(id_fam)

tab wealth_R_10
/// tab 287 observations
drop if wealth_R_10==.

sum wealth_R_10 wealth_R_15 wealth_R_20
///92 drop-outs

preserve
keep if wealth_R_20==.
keep if wealth_R_10 <200
sum id_fam
restore 
///20 drop-outs

gen wealth_R_10_LN = ln(wealth_R_10)
gen wealth_R_15_LN = ln(wealth_R_15)
gen wealth_R_20_LN = ln(wealth_R_20)

reg wealth_R_15_LN wealth_R_10_LN
reg wealth_R_20_LN wealth_R_10_LN

label var wealth_R_15_LN "2015"
label var wealth_R_20_LN "2020"


grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1
grstyle set legend 10, inside nobox
grstyle set ci, opacity(40) 


cd "$mypath/output/figures/"


twoway (scatter wealth_R_15_LN wealth_R_10_LN, msymb(O) mcolor(black%60) msize()) ///
(scatter wealth_R_20_LN wealth_R_10_LN, msymb(D) mcolor(gs11%60) msize()) ///
(lfitci wealth_R_15_LN wealth_R_10_LN, clstyle(black)) ///
(lfitci wealth_R_20_LN wealth_R_10_LN, clstyle(gs11)) ///
, ytitle("real log wealth 2015 resp. 2020", size(normalsize)) xtitle("real log wealth 2010", size(normalsize)) ylab(5(1)11, labsize(normalsize) grid gmin gmax) xlab(5(1)11, labsize(normalsize) grid gmin gmax) ///
legend(order(1 "2015" 2 "2020")) note("92 of 287 observations (32%) drop out from 2010 to 2020." ///
"20 of the 92 drop out obs. (22%) had a net wealth of <0.2 billion in 2010.", size(small)) text(10.8 9.5 "{&beta} = 1.00" "R{superscript:2} = 0.79", size(normalsize) color(gs11)) ///
text(10.0 10.5 "{&beta} = 1.02" "R{superscript:2} = 0.89", size(normalsize) color(black))

graph export "mob_corr_fam_1020.pdf", as(pdf) replace



**dynastie analysis: 2000-2020**
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

keep if year==2000 | year==2010 | year==2020 
sort id_fam year				
	
gen wealth_R_00 = .
replace wealth_R_00 = wealth_R if year==2000

gen wealth_R_10 = .
replace wealth_R_10 = wealth_R if year==2010
	
gen wealth_R_20 = .
replace wealth_R_20 = wealth_R if year==2020


collapse (mean) wealth_R_00 (mean) wealth_R_10 (mean) wealth_R_20, by(id_fam)

gen wealth_R_00_LN = ln(wealth_R_00)
gen wealth_R_10_LN = ln(wealth_R_10)
gen wealth_R_20_LN = ln(wealth_R_20)

reg wealth_R_10_LN wealth_R_00_LN
reg wealth_R_20_LN wealth_R_10_LN

label var wealth_R_10_LN "2000-2010"
label var wealth_R_20_LN "2010-2020"

grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1
grstyle set legend 10, inside nobox
grstyle set ci, opacity(40) 

cd "$mypath/output/figures/"


twoway (scatter wealth_R_10_LN wealth_R_00_LN, msymb(O) mcolor(black%60) msize()) ///
(scatter wealth_R_20_LN wealth_R_10_LN, msymb(D) mcolor(gs11%60) msize()) ///
(lfitci wealth_R_10_LN wealth_R_00_LN, clstyle(black)) ///
(lfitci wealth_R_20_LN wealth_R_10_LN, clstyle(gs11)) ///
, ytitle("real log wealth in t+10", size(normalsize)) xtitle("real log wealth in t", size(normalsize)) ///
ylab(5(1)11, labsize(normalsize) grid gmin gmax) xlab(5(1)11, labsize(normalsize) grid gmin gmax) ///
legend(order(1 "2000-2010" 2 "2010-2020") size(normalsize)) text(10.1 10.6 "{&beta} = 1.00" "R{superscript:2} = 0.79", size(normalsize) color(gs11)) ///
text(8.3 9.9 "{&beta} = 0.80" "R{superscript:2} = 0.67", size(normalsize) color(black)) ///
note("105 of 270 observations (39%) drop out from 2000 to 2010; of which 29% had a net wealth of <0.2 billion in 2000." /// 
"  92 of 287 observations (32%) drop out from 2010 to 2020; of which 22% had a net wealth of <0.2 billion in 2010.", size(small)) 

graph display, ysize(12) xsize(20) 

graph export "mob_corr_fam_0020.pdf", as(pdf) replace


******************************************************************************************************************************************

** individual analysis: 2000-2010**	
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear
	
keep if year==2000 | year==2005 | year==2010 
sort id_pers year				
	
gen wealth_R_00 = .
replace wealth_R_00 = wealth_R if year==2000
gen wealth_R_05 = .
replace wealth_R_05 = wealth_R if year==2005
gen wealth_R_10 = .
replace wealth_R_10 = wealth_R if year==2010

collapse (mean) wealth_R_00 (mean) wealth_R_05 (mean) wealth_R_10, by(id_pers)



tab wealth_R_00
/// tab 281 observations
drop if wealth_R_00==.

sum wealth_R_00 wealth_R_05 wealth_R_10
///140 drop-outs

preserve
keep if wealth_R_10==.
keep if wealth_R_00 <200
sum id_pers
restore 
///35 with below 0.2b wealth_R

gen wealth_R_00_LN = ln(wealth_R_00)
gen wealth_R_05_LN = ln(wealth_R_05)
gen wealth_R_10_LN = ln(wealth_R_10)

reg wealth_R_05_LN wealth_R_00_LN
reg wealth_R_10_LN wealth_R_00_LN

label var wealth_R_05_LN "2005"
label var wealth_R_10_LN "2010"


grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1
grstyle set legend 10, inside nobox
grstyle set ci, opacity(40) 

cd "$mypath/output/figures/"


twoway (scatter wealth_R_05_LN wealth_R_00_LN, msymb(O) mcolor(black%60) msize()) ///
(scatter wealth_R_10_LN wealth_R_00_LN, msymb(D) mcolor(gs11%60) msize()) ///
(lfitci wealth_R_05_LN wealth_R_00_LN, clstyle(black) lwidth() ) ///
(lfitci wealth_R_10_LN wealth_R_00_LN, clstyle(gs11)) ///
, ytitle("real log wealth 2005 resp. 2010", size(normalsize)) xtitle("real log wealth 2000", size(normalsize)) ylab(5(1)10, labsize(normalsize) grid gmin gmax) xlab(5(1)10, labsize(normalsize) grid gmin gmax) ///
legend(order(1 "2005" 2 "2010") size(normalsize)) note("140 of 281 observations (50%) drop out from 2000 to 2010." ///
"35 of the 140 drop out obs. (25%) had a net wealth of <0.2 billion in 2000.", size(small)) text(8.2 9.6 "{&beta} = 0.80" "R{superscript:2} = 0.69", size(normalsize) color(gs11)) ///
text(9.6 9.1 "{&beta} = 0.88" "R{superscript:2} = 0.83", size(normalsize) color(black))

graph export "mob_corr_ind_0010.pdf", as(pdf) replace


**individual analysis: 2010-2020**	
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear
	
keep if year==2010 | year==2015 | year==2020 
sort id_pers year				
	
gen wealth_R_10 = .
replace wealth_R_10 = wealth_R if year==2010
gen wealth_R_15 = .
replace wealth_R_15 = wealth_R if year==2015
gen wealth_R_20 = .
replace wealth_R_20 = wealth_R if year==2020

collapse (mean) wealth_R_10 (mean) wealth_R_15 (mean) wealth_R_20, by(id_pers)

tab wealth_R_10
/// tab 291 observations
drop if wealth_R_10==.

sum wealth_R_10 wealth_R_15 wealth_R_20
///127 drop-outs

preserve
keep if wealth_R_20==.
keep if wealth_R_10 <200
sum id_pers
restore 
///23 drop-outs


gen wealth_R_10_LN = ln(wealth_R_10)
gen wealth_R_15_LN = ln(wealth_R_15)
gen wealth_R_20_LN = ln(wealth_R_20)

reg wealth_R_15_LN wealth_R_10_LN
reg wealth_R_20_LN wealth_R_10_LN

label var wealth_R_15_LN "2015"
label var wealth_R_20_LN "2020"

grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1
grstyle set legend 10, inside nobox
grstyle set ci, opacity(40) 


cd "$mypath/output/figures/"

twoway (scatter wealth_R_15_LN wealth_R_10_LN, msymb(O) mcolor(black%60) msize()) ///
(scatter wealth_R_20_LN wealth_R_10_LN, msymb(D) mcolor(gs11%60) msize()) ///
(lfitci wealth_R_15_LN wealth_R_10_LN, clstyle(black)) ///
(lfitci wealth_R_20_LN wealth_R_10_LN, clstyle(gs11)) ///
, ytitle("real log wealth 2015 resp. 2020", size(normalsize)) xtitle("real log wealth 2010", size(normalsize)) ylab(5(1)11, labsize(normalsize) grid gmin gmax) xlab(5(1)11, labsize(normalsize) grid gmin gmax) ///
legend(order(1 "2015" 2 "2020")) note("127 of 291 observations (44%) drop out from 2010 to 2020." ///
"23 of the 127 drop out obs. (18%) had a net wealth of <0.2 billion in 2010.", size(small)) text(10.8 9.5 "{&beta} = 1.01" "R{superscript:2} = 0.79", size(normalsize) color(gs11)) ///
text(10.0 10.5 "{&beta} = 1.02" "R{superscript:2} = 0.90", size(normalsize) color(black))

graph export "mob_corr_ind_1020.pdf", as(pdf) replace


***individual analysis: 2000-2020**	
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

keep if year==2000 | year==2010 | year==2020 
sort id_pers year				
	
gen wealth_R_00 = .
replace wealth_R_00 = wealth_R if year==2000

gen wealth_R_10 = .
replace wealth_R_10 = wealth_R if year==2010
	
gen wealth_R_20 = .
replace wealth_R_20 = wealth_R if year==2020

collapse (mean) wealth_R_00 (mean) wealth_R_10 (mean) wealth_R_20, by(id_pers)

gen wealth_R_00_LN = ln(wealth_R_00)
gen wealth_R_10_LN = ln(wealth_R_10)
gen wealth_R_20_LN = ln(wealth_R_20)

reg wealth_R_10_LN wealth_R_00_LN
reg wealth_R_20_LN wealth_R_10_LN


label var wealth_R_10_LN "2000-2010"
label var wealth_R_20_LN "2010-2020"

grstyle init
grstyle set plain, horizontal grid
grstyle set color Set1
grstyle set legend 10, inside nobox
grstyle set ci, opacity(40) 

cd "$mypath/output/figures/"


twoway (scatter wealth_R_10_LN wealth_R_00_LN, msymb(O) mcolor(black%60) msize()) ///
(scatter wealth_R_20_LN wealth_R_10_LN, msymb(D) mcolor(gs11%60) msize()) ///
(lfitci wealth_R_10_LN wealth_R_00_LN, clstyle(black)) ///
(lfitci wealth_R_20_LN wealth_R_10_LN, clstyle(gs11)) ///
, ytitle("real log wealth in t+10", size(normalsize)) xtitle("real log wealth in t", size(normalsize)) ///
ylab(5(1)11, labsize(normalsize) grid gmin gmax) xlab(5(1)11, labsize(normalsize) grid gmin gmax) ///
legend(order(1 "2000-2010" 2 "2010-2020") size(normalsize)) text(10.1 10.0 "{&beta} = 1.01" "R{superscript:2} = 0.79", size(normalsize) color(gs11)) ///
text(8.3 9.9 "{&beta} = 0.80" "R{superscript:2} = 0.69", size(normalsize) color(black)) ///
note("140 of 281 observations (50%) drop out from 2000 to 2010; of which 25% had a net wealth of <0.2 billion in 2000." /// 
"127 of 291 observations (44%) drop out from 2010 to 2020; of which 18% had a net wealth of <0.2 billion in 2010.", size(small)) 

graph display, ysize(12) xsize(20) 

graph export "mob_corr_ind_0020.pdf", as(pdf) replace



		